<?php
require(dirname(__FILE__) . '/../../includes/global.php');
$tbl_faq = $_TABLES['faq'];

$action = $_GET['action'];
if($action == 'add') {
    $conn   = & get_db_conn();
    $data   = array(
        'cid'     => @(int)$_POST['cid'],
        'cata_id' => @(int)$_POST['cata_id'],
        'subject' => iconv("UTF-8", "GBK", trim($_POST['subject'])),
        'content' => iconv("UTF-8", "GBK", trim($_POST['content'])),

        'sender'        => iconv("UTF-8", "GBK", trim($_POST['sender'])),
        'senderemail'   => iconv("UTF-8", "GBK", trim($_POST['sender_email'])),
        'email2sender'  => @(int)$_POST['email_to_sender'],
        'sendtime'      => $timestamp,
        'ip' => get_ip(),
        'display'   => 0,
        'reply'     => '',
        );



    if($data['cata_id'] <= 0) {
        echo 'error';
        exit();
    }

    if($data['cid'] <= 0) {
        $data['cid'] = $data['cata_id'];
    }



    if($conn->AutoExecute($tbl_faq,$data,'INSERT')) {
        echo 'ok';
    }
} elseif($action == 'query') {
    $code   = trim($_REQUEST['code']);
    $front  = @(int)$_REQUEST['front'];
    @session_start();


    if(strtolower($code) == strtolower($_SESSION[$G_front_session_key]['validate_code'])) {
        echo "ok";
    } else {
        echo "error";
    }
    $_SESSION[$G_front_session_key]['validate_code'] = false;
}
?>